package com.speech.net.constant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by XuLH on 2018/6/21.
 */
public enum EnumResultCode
{
    //无
    NONE(0L),

    成功(1L),

    //没有登记IP的设备都需要登记，防止非法IP的数据攻击
    设备需登记(0x40000000L | 0x0001L),   //1073741825

    //需要重新登录
    非法设备ID(0x40000000L | 0x0002L),  //1073741826

    注册手机已存在(0x40000000L | 0x0101L), //1073742081

    邀请码错误(0x40000000L | 0x0102L),   //1073742082

    需要登录(0x40000000L | 0x0200L),    //1073742336

    //需要重新登录
    登录过期(0x40000000L | 0x0201L),    //1073742337

    //用户名不存在
    登录名不存在(0x40000000L | 0x0203L),  //1073742339

    //密码错误
    登录密码错误(0x40000000L | 0x0204L),  //1073742340

    验证码验证失败(0x40000000L | 0x0300L), //1073742592

    验证码错误(0x40000000L | 0x0301L),   //1073742593

    验证码超时(0x40000000L | 0x0302L),   //1073742594

    今日申请验证码太多(0x40000000L | 0x0303L),   //1073742595

    这小时申请验证码太多(0x40000000L | 0x0304L),  //1073742596


    申请句子太频繁(0x40000000L | 0x0601L), //1073743361

    今日已签到(0x40000000L | 0x0801L),   //1073743873

    今日的币挖完了(0x40000000L | 0x0802L), //1073743874

    //上传的句子 hash 不对
    句子特征非法(0x40000000L | 0x0803L),  //1073743875


    服务器错误(0x40000000L | 0xFF01L),   //1073807105

    解压数据错误(0x40000000L | 0xFF02L),  //1073807106

    通信格式错误(0x40000000L | 0xFF03L),  //1073807107

    //具体查看数据字段才知道是啥错误
    通用错误(0x40000000L | 0xFFFFFFL),  //1090519039
    ;

    public static final Long MASK_ERROR = 0x40000000L;

    private final Long value;

    private static Map<Long, EnumResultCode> mapV2E = new ConcurrentHashMap<>();

    static {
        for (EnumResultCode c: EnumResultCode.values()){
            mapV2E.put(c.value(), c);
        }
    }

    EnumResultCode(Long v) {value=v;}
    @JsonValue
    public Long value() {return value;}

    @JsonCreator
    public static EnumResultCode fromValue(Long val) {
        if(val==null) return null;
        EnumResultCode ret = mapV2E.get(val);
        if(ret==null) ret = NONE;
        return ret;
    }
}
